package cn.gbase.jiangsu.data.transfer.action;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

import cn.gbase.jiangsu.data.transfer.bean.CompanyUser;
import cn.gbase.jiangsu.data.transfer.bean.StartEndDate;
import cn.gbase.jiangsu.data.transfer.bean.StartEndDateCompany;
import cn.gbase.jiangsu.data.transfer.bean.SupplierUser;
import cn.gbase.jiangsu.data.transfer.service.CompanyCountService;
import cn.gbase.jiangsu.data.transfer.util.DateUtil;

@IocBean
@At("/companyCountByDateAction")
public class CompanyCountByDateAction {

	@Inject
	private CompanyCountService companyCountService;

	@At("/showStartEndDateDetail/*")
	@Ok("jsp:/supplierCw/showStartEndDateDetail")
	public Object showStartEndDateDetail(@Param("startDate") String startDate, @Param("endDate") String endDate,
			HttpSession session) {
		SupplierUser u = (SupplierUser) session.getAttribute("supplierUser");
		Date startD = startDate == null ? new Date() : DateUtil.toDate(startDate, "yyyy-MM-dd");
		Date endD = endDate == null ? new Date() : DateUtil.toDate(endDate, "yyyy-MM-dd");
		List<StartEndDate> strDateList = companyCountService.countAllSupplierByDate(startD, endD, u);
		return strDateList;
	}

	@At("/showStartEndDateCompanyDetail/*")
	@Ok("jsp:/companyCw/showStartEndDateCompanyDetail")
	public Object showStartEndDateCompanyDetail(@Param("startDate") String startDate, @Param("endDate") String endDate,
			HttpSession session) {
		CompanyUser u = (CompanyUser) session.getAttribute("companyUser");
		Date startD = startDate == null ? new Date() : DateUtil.toDate(startDate, "yyyy-MM-dd");
		Date endD = endDate == null ? new Date() : DateUtil.toDate(endDate, "yyyy-MM-dd");
		List<StartEndDateCompany> strDateList = companyCountService.countAllCompanyByDate(startD, endD, u);
		return strDateList;
	}
}
